package com.mingmen.canting.gongyingshang;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mingmen.canting.R;
import com.mingmen.canting.model.ShopListModel;

import java.util.List;


public class GongYingProductAdapter extends RecyclerView.Adapter<GongYingProductAdapter.ViewHolder> {
    List<ShopListModel.DataBean> myLiveList;
    Context mContext;
    private OnItemClickListener mOnItemClickListener;


    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClickListener(View view, int pos, List<ShopListModel.DataBean> myLiveList);
    }


    public GongYingProductAdapter(Context context, List<ShopListModel.DataBean> list) {
        this.mContext = context;
        this.myLiveList = list;

    }

    public void setDataList(List<ShopListModel.DataBean> list) {
        myLiveList = list;

        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_gongyingproduct, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }



    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        ShopListModel.DataBean myLive = myLiveList.get(holder.getAdapterPosition());


        holder.checkbox.setChecked(myLive.isChecked());

        holder.mTvTitle.setText(myLive.getCommodityName());



        holder.checkbox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                myLive.setChecked(!myLive.isChecked());
                holder.checkbox.setChecked(myLive.isChecked());

                mOnItemClickListener.onItemClickListener(view, position, myLiveList);
            }
        });

    }

    @Override
    public int getItemCount() {
        return myLiveList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {


        TextView mTvTitle;

        ImageView ivAvatar;


        CheckBox checkbox;
        LinearLayout content;




        LinearLayout layout_guige;


        public ViewHolder(View itemView) {
            super(itemView);

            mTvTitle = (TextView) itemView.findViewById(R.id.tvCity);
            ivAvatar = (ImageView) itemView.findViewById(R.id.ivAvatar);

            checkbox = (CheckBox) itemView.findViewById(R.id.checkbox);
            content = (LinearLayout) itemView.findViewById(R.id.content);

            layout_guige = itemView.findViewById(R.id.layout_guige);

        }
    }


}
